package com.motus.pm.daoImpl;


import java.util.*;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.motus.pm.dao.ProjectPhaseDao;
import com.motus.pm.vo.PmProjectPhase;

@Repository
public class ProjectPhaseDaoImpl extends BaseDaoImpl<PmProjectPhase> implements ProjectPhaseDao {

	@Autowired
	private SessionFactory sessionFactory;
	
	@SuppressWarnings("unchecked")
	@Override
	public List<PmProjectPhase> getProjectPhasesByPid(String pid) {
		Session session=sessionFactory.getCurrentSession();
		String hql="from PmProjectPhase p where p.id.pmProjectInfo.pid=?";
		Query query=session.createQuery(hql);
		query.setString(0, pid);
		return query.list();
	}

	@Override
	public List<PmProjectPhase> getProjectPhasesByDeptId(int deptId) {
		Session session=sessionFactory.getCurrentSession();
		String sql="select * from pm_project_phase where pm_project_phase.phase_id in"+
				   "(select phase_id from pm_phase_info where depart_id=?)"+
				   "ORDER BY phase_plan_start_time desc";
		Query query=session.createSQLQuery(sql).addEntity(PmProjectPhase.class);
		query.setInteger(0, deptId);
		
		@SuppressWarnings("unchecked")
		List<PmProjectPhase> pmProjectPhases=query.list();
		return pmProjectPhases;
	}

}
